<?php

class Core_Form_Admin_Settings_Mail extends Core_Form_Admin_Settings_Abstract
{
	public function init()
	{
	    $this->setTitle('mail settings');
        $this->setDescription("core.form.admin.mail.desc");
        
		$domain =  isset($_REQUEST['HTTP_HOST'])?$_REQUEST['HTTP_HOST']:'';
		
		if(empty($domain) || $domain == '127.0.0.1' OR $domain == 'localhost'){
			$domain = 'example.com';
		}
		// contact to email
		$this -> addElement('text', 'mail_contact', array(
				'label' => 'contact email',
				'required' => 1,
				'class' => 'email long-text',
				'value' => 'info@'. $domain,
				'validators' => array('EmailAddress'),
		));

		// mail reply to name
		$this -> addElement('text', 'mail_reply_name', array(
				'label' => 'reply to name',
				'required' => 1,
				'class' => 'text long-text',
				'filters' => array('StringTrim'),
				'value'=>'no-reply',
		));

		// mail reply to address
		$this -> addElement('text', 'mail_reply_email', array(
				'label' => 'reply to email',
				'required' => 1,
				'class' => 'email long-text',
				'value' => 'no-reply@'. $domain,
				'validators' => array('EmailAddress'),
		));

		// mail send from name
		$this -> addElement('text', 'mail_from_name', array(
				'label' => 'from name',
				'required' => 1,
				'value'=>'support team',
				'class' => 'text long-text',
				'filters' => array('StringTrim'),
		));

		// mail send from address
		$this -> addElement('text', 'mail_from_email', array(
				'label' => 'from email',
				'required' => 1,
				'class' => 'email long-text',
				'value' => 'info@'.$domain,
				'validators' => array('EmailAddress'),
		));

		// use mail queue ?
		$this -> addElement('radio', 'mail_queue', array(
				'label' => 'use queue',
				'multiOptions' => array(
					'on'=>'yes, enable mail queue',
					'off'=>'no, disable mail queue',
				),
				'value'=>'on',
				'description'=>'mail queue is helpful when you send a large of amount email without be blocked by mail service.',
		));
		
		// mail method ?
		$this->addElement('radio','mail_protocol',array(
			'label'=>'send mail method',
			'multiOptions'=>array(
				'smtp'=>'send mail via SMTP.',
				'mail'=>'send mail via built-in mail function, it is unsecure &amp; unsafe.'				
			),
			'value'=>'mail'
		));
		
		// smtp server
		$this->addElement('text','mail_smtp_host',array(
			'label'=>'smtp host name',
			'value'=>$domain,
			'class'=>'text long-text',
		));
		
		// smtp port
		$this->addElement('text','mail_smtp_port',array(
			'label'=>'smtp port',
			'value'=>'25',
			'class'=>'text long-text',
			'description'=>'25,465',
			'validators'=>array('Int'),
		));
		
		// smtp authenticate
		$this->addElement('radio','mail_smtp_authenticate',array(
			'label'=>'send mail method',
			'multiOptions'=>array(
				'on'=>'yes, smtp require authenticate.',
				'off'=>'no, smtp does not require authenticate.'				
			),
			'value'=>'off'
		));
		
		// smtp username
		$this->addElement('text','mail_smtp_username',array(
			'label'=>'smtp username',
			'value'=>'info@'.$domain,
			'class'=>'text long-text',
		));
		
		// smtp password
		$this->addElement('text','mail_smtp_password',array(
			'label'=>'smtp password',
			'value'=>'******',
			'class'=>'text long-text',
		));
		
		// smtp  secure protocol
		$this->addElement('radio','mail_smtp_secure',array(
			'label'=>'smtp secure protocol',
			'multiOptions'=>array(
				'none'=>'none, does not secure.',
				'ssl'=>'SSL protocol.',
				'tsl'=>'TSL protocol.',
			),
			'value'=>'none',
		));
		
		// init submit
		$this -> addElement('button', '_submit', array(
				'label' => 'save change',
				'type' => 'submit',
				'class' => 'submit',
				'decorators' => array('ViewHelper')
		));
        
        // init _test
        $this -> addElement('button', '_test', array(
                'label' => 'test settings',
                'type' => 'button',
                'class' => 'submit',
                'decorators' => array('ViewHelper')
        ));
		
		// init submit
		$this -> addElement('button', '_cancel', array(
				'label' => 'cancel',
				'type' => 'submit',
				'class' => 'cancel',
				'decorators' => array('ViewHelper')
		));

		$this -> addDisplayGroup(array(
				'_submit',
				'_test',
				'_cancel'
		), '_buttons');
	}

}
